#ifndef SMARTLINKSERVENFROMJAVA_H
#define SMARTLINKSERVENFROMJAVA_H

#include <QObject>
#include <QtAndroidExtras/QAndroidJniObject>
#include <QDebug>
#include <QtAndroidExtras>
#include <QAndroidJniEnvironment>

class SmartLinkServenFromJava : public QObject
{
    Q_OBJECT
public:
    explicit SmartLinkServenFromJava(QObject *parent = 0);
    static SmartLinkServenFromJava * root;
    ~SmartLinkServenFromJava(){}
//    static SmartLinkServenFromJava* getInstall()
//    {
//        if(root==NULL) {
//            root=new SmartLinkServenFromJava();
//        }
//        return root;
//    }

    Q_INVOKABLE static QString getSSID();
    Q_INVOKABLE static bool startLink(QString ssid,QString password);
    static void hiQt(JNIEnv *env,jobject thiz)
    {

        qDebug()<<"hiQt";
    }
    static void hiQt2(JNIEnv *env,jobject thiz)
    {
        qDebug()<<"hiQt2";
    }
    static void javaSignal(JNIEnv *env,jobject thiz,jint index) {
         qDebug()<<"java触";
        int cindex=index ;
        qDebug()<<"java触发："<<cindex;
    }

    bool registerNativeMthode()
    {
        JNINativeMethod methods[]{
            {"hiQt","()V",(void*)hiQt},
            {"hiQt2","()V",(void*)hiQt2},
            {"javaSignal","(I)V",(void*)javaSignal}
        };
        const char *classname=
                "an/qt/hello/NativeFunction";
        jclass clazz;
        QAndroidJniEnvironment env;
        QAndroidJniObject javaClass(classname);
        clazz=env->GetObjectClass(javaClass.object<jobject>());


        //    clazz=env->FindClass(classname);会使之无法启动
        bool result=false;
        if(clazz)
        {
            jint ret=env->RegisterNatives(clazz,methods,
                                          sizeof(methods)/sizeof(methods[0]));
            env->DeleteLocalRef(clazz);
            result=(ret>=0);
        }
        if(env->ExceptionCheck()) env->ExceptionClear();
        return result;
    }
signals:

public slots:

private :

};

#endif // SMARTLINKSERVENFROMJAVA_H
